package com.zm.listener;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.zm.jdbc.AccessDb;

public class ApplicationListener implements ServletContextAttributeListener,
		ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		    ServletContext application=arg0.getServletContext();
            AccessDb db=(AccessDb) application.getAttribute("accessdb");
            if(db!=null)
            	db.destroy();
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		AccessDb db=new AccessDb();
		ServletContext application=arg0.getServletContext();
		application.setAttribute("accessdb",db);
	    List<String> onlineUser=new ArrayList<String>();
	    application.setAttribute("onlinelist",onlineUser);

	}

	@Override
	public void attributeAdded(ServletContextAttributeEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void attributeRemoved(ServletContextAttributeEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void attributeReplaced(ServletContextAttributeEvent arg0) {
		// TODO Auto-generated method stub

	}

}
